-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix corrupt reads. #61
Conversation
Now continuously reads from stream in chunks until whole message is received
I guess I need to add a test the reads a message with length. |
Yeah ... if you can do it, would be awesome :) |
Having a bit of trouble, don't quite get why |
All the test suite is going to be refactored and probably rewritten, as you can see in #60. Your problem may be due we are currently mocking all the NATS server but I'm moving everything to use a real NATS server thanks to Docker support on Travis. If you have problems, no worries I can merge this without the proper test and I will add it once we use the real server 😉 |
Yeah, I've a feeling this will be fixed by sending via the real thing :) |
Would be great to get this in ASAP since it's basically quite a breaking bug. |
I will merge this tonight. 👍 |
sweet! :) |
LGTM |
Thanks @repejota :) |
$receivedBytes += $chunkSize; | ||
} | ||
if (strlen($line) > 2) { | ||
$line = substr($line, 0, -2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line create the regression, basically if there is escape char at the end of message, using rtrim is safer, but I'm not sure if the need to be done here. Maybe you should double check if you don't introduce those two bytes in your own code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at home but I will look at it ASAP. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're probably right that I don't need to trim those, I'm using protobuf on the wire and had a corrupt message initially when I didn't trim them but that must have been caused by something else I was doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just had a look at the spec for MSG and the payload length doesn't include the \r\n at the end, from the example at http://nats.io/documentation/internals/nats-protocol/#a-name-msg-a-msg:4b9a176fc3df6b183e7b5ba0c60737ef.
I believe I added this line since initially I had incorrectly set if ( $bytesLeft < 1500 )
instead of the correct if ( $bytesLeft < $this->chunksize )
, and that ended up reading in the \r\n at the end in cases.
Removing the substr
section seems to work fine locally for me.
Now continuously reads from stream in chunks until whole message is received.
Apparently
fread
stops when first packet is received, regardless if that's the whole message.